package com.mall.common;

import java.io.Serializable;
import java.math.BigDecimal;

import javax.validation.constraints.Size;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.NotBlank;

public class CommonSetting implements Serializable {
	private static final long serialVersionUID = -491940816474981155L;

	// 货币种类（人民币、美元、欧元、英磅、加拿大元、澳元、卢布、港币、新台币、韩元、新加坡元、新西兰元、日元、马元、瑞士法郎、瑞典克朗、丹麦克朗、兹罗提、挪威克朗、福林、捷克克朗、葡币）
	public enum CurrencyType {
		CNY, USD, EUR, GBP, CAD, AUD, RUB, HKD, TWD, KRW, SGD, NZD, JPY, MYR, CHF, SEK, DKK, PLZ, NOK, HUF, CSK, MOP
	};
	
	// 小数位精确方式（四舍五入、向上取整、向下取整）
	public enum RoundType {
		roundHalfUp, roundUp, roundDown
	}
		
	private String name;//系统名称
	 /** 网站logo **/
    private String logo;
    /** 域名 **/
    private String domain;
    /** 域名别名 **/
    private String domainAlias;
    /** 端口号 **/
    private Integer port;
    /** 部署路径 **/
    private String contextPath;
    /** 公司名称 **/
    private String company;
    /** 网站拥有者姓名 **/
    private String owner_name;
    /** 网站拥有者身份证号 **/
    private String owner_identity;
    /** 电话号码 **/
    private String phone;
    /** 联系地址 **/
    private String address;
    /** 手机号码 **/
    private String mobile;
    /** 网站拥有者电子邮箱 **/
    private String owner_email;
    /** 版权信息 **/
    private String copyright;
    /** 邮编 **/
    private String zipCode;
    
    /** 货币种类 **/
    private CurrencyType currencyType;
    /** 货币符号 **/
    private String currencySign;
    /** 货币单位 **/
    private String currencyUnit;
    /** 商品价格精确位数 **/
    private Integer priceScale;
    /** 商品价格精确方式 **/
    private RoundType priceRoundType;
    /** 订单金额精确位数 **/
    private Integer orderScale;

    /** 允许上传的文件大小 **/
    private Integer uploadLimit;
    private String uploadFlashExtension; //允许上传的flash文件扩展名
    private String uploadImageExtension;// 允许上传的图片文件扩展名（为空表示不允许上传图片文件）
	private String uploadMediaExtension;// 允许上传的媒体文件扩展名（为空表示不允许上传媒体文件）
	private String uploadFileExtension;// 允许上传的文件扩展名（为空表示不允许上传文件）
	private String imageUploadPath;
	private String flashUploadPath;
	private String mediaUploadPath;
	private String fileUploadPath;
    
	private Boolean isAdminLoginFailureLock;// 后台登录错误是否锁定
	private Integer adminLoginFailureLockCount;
	private Integer adminLoginFailureLockTime;// 登录失败锁定时间
	
	/** 前台地址 **/
	private String frontUrl;

    // ===============邮件设置===========================
    /** 发件人邮箱 **/
    private String smtpFromMail;
    /** SMTP服务器地址 **/
    private String smtpHost;
    /** SMTP服务器端口 **/
    private Integer smtpPort;
    /** SMTP用户名 **/
    private String smtpUsername;
    /** SMTP密码 **/
    private String smtpPassword;
    /** HTML自动生成延时 **/
    private Integer buildHtmlDelayTime;
    
    private String defaultImg;//默认图片

	//价格处理精度
	public BigDecimal setScale(BigDecimal amount) {
		if (amount == null) {
			return null;
		}
		int roundingMode;
		if (getPriceRoundType() == RoundType.roundUp) {
			roundingMode = 0;
		} else {
			if (getPriceRoundType() == RoundType.roundDown) {
				roundingMode = 1;
			} else {
				roundingMode = 4;
			}
		}
		return amount.setScale(getPriceScale().intValue(), roundingMode);
	}

	public StringBuilder getUrlBuff(boolean flag){
        StringBuilder stringbuilder = new StringBuilder();
        if(flag){
            stringbuilder = (new StringBuilder("http://")).append(getDomain());
            Integer integer = getPort();
            if(integer != null && integer.intValue() != 80 && integer.intValue() != 0){
                stringbuilder.append(":").append(integer);
            }
        }
		if(StringUtils.isNotBlank(getContextPath())){
			stringbuilder.append(getContextPath());
		}
        return stringbuilder;
    }

	public String[] getUploadImageExtensions() {
		return StringUtils.split(uploadImageExtension, ",");
	}
	
	public String[] getUploadMediaExtensions() {
		return StringUtils.split(uploadMediaExtension, ",");
	}

	public String[] getUploadFileExtensions() {
		return StringUtils.split(uploadFileExtension, ",");
	}

	public String[] getUploadFlashExtensions() {
		return StringUtils.split(uploadFlashExtension, ",");
	}

	public Boolean getIsAdminLoginFailureLock() {
		return isAdminLoginFailureLock;
	}

	public void setIsAdminLoginFailureLock(Boolean isAdminLoginFailureLock) {
		this.isAdminLoginFailureLock = isAdminLoginFailureLock;
	}

	public Integer getAdminLoginFailureLockCount() {
		return adminLoginFailureLockCount;
	}

	public void setAdminLoginFailureLockCount(Integer adminLoginFailureLockCount) {
		this.adminLoginFailureLockCount = adminLoginFailureLockCount;
	}

	public Integer getAdminLoginFailureLockTime() {
		return adminLoginFailureLockTime;
	}

	public void setAdminLoginFailureLockTime(Integer adminLoginFailureLockTime) {
		this.adminLoginFailureLockTime = adminLoginFailureLockTime;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getLogo() {
		return logo;
	}

	public void setLogo(String logo) {
		this.logo = logo;
	}

	public String getDomain() {
		return domain;
	}

	public void setDomain(String domain) {
		this.domain = domain;
	}

	public String getDomainAlias() {
		return domainAlias;
	}

	public void setDomainAlias(String domainAlias) {
		this.domainAlias = domainAlias;
	}

	public String getCompany() {
		return company;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public String getOwner_name() {
		return owner_name;
	}

	public void setOwner_name(String owner_name) {
		this.owner_name = owner_name;
	}

	public String getOwner_identity() {
		return owner_identity;
	}

	public void setOwner_identity(String owner_identity) {
		this.owner_identity = owner_identity;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getOwner_email() {
		return owner_email;
	}

	public void setOwner_email(String owner_email) {
		this.owner_email = owner_email;
	}

	public String getCopyright() {
		return copyright;
	}

	public void setCopyright(String copyright) {
		this.copyright = copyright;
	}

	public String getZipCode() {
		return zipCode;
	}

	public void setZipCode(String zipCode) {
		this.zipCode = zipCode;
	}
	
	@NotBlank(message="货币种类不允许为空!")
	public CurrencyType getCurrencyType() {
		return currencyType;
	}

	public void setCurrencyType(CurrencyType currencyType) {
		this.currencyType = currencyType;
	}

	@NotBlank(message = "货币符号不允许为空!")
	public String getCurrencySign() {
		return currencySign;
	}

	public void setCurrencySign(String currencySign) {
		this.currencySign = currencySign;
	}

	@NotBlank(message = "货币单位不允许为空!")
	public String getCurrencyUnit() {
		return currencyUnit;
	}

	public void setCurrencyUnit(String currencyUnit) {
		this.currencyUnit = currencyUnit;
	}

	@NotBlank(message="商品价格精确位数不允许为空!")
    @Size(min = 0, max = 14, message="长度应该介于0和14之间")
    public Integer getPriceScale() {
        return priceScale;
    }

    public void setPriceScale(Integer priceScale) {
        this.priceScale = priceScale;
    }

    @NotBlank(message="订单金额精确位数不允许为空!")
    @Size(min=0, max=4, message="订单金额精确位数必须为零或小于4!")
    public Integer getOrderScale() {
        return orderScale;
    }

    public void setOrderScale(Integer orderScale) {
        this.orderScale = orderScale;
    }
    
    @NotBlank(message="商品价格精确方式不允许为空!")
    public RoundType getPriceRoundType() {
        return priceRoundType;
    }

    public void setPriceRoundType(RoundType priceRoundType) {
        this.priceRoundType = priceRoundType;
    }
    
    public Integer getUploadLimit() {
		return uploadLimit;
	}

	public void setUploadLimit(Integer uploadLimit) {
		this.uploadLimit = uploadLimit;
	}

	public String getUploadFlashExtension() {
		return uploadFlashExtension;
	}

	public void setUploadFlashExtension(String uploadFlashExtension) {
		this.uploadFlashExtension = uploadFlashExtension;
	}

	public String getUploadImageExtension() {
		return uploadImageExtension;
	}

	public void setUploadImageExtension(String uploadImageExtension) {
		this.uploadImageExtension = uploadImageExtension;
	}

	public String getUploadMediaExtension() {
		return uploadMediaExtension;
	}

	public void setUploadMediaExtension(String uploadMediaExtension) {
		this.uploadMediaExtension = uploadMediaExtension;
	}

	public String getUploadFileExtension() {
		return uploadFileExtension;
	}

	public void setUploadFileExtension(String uploadFileExtension) {
		this.uploadFileExtension = uploadFileExtension;
	}

	public String getImageUploadPath() {
		return imageUploadPath;
	}

	public void setImageUploadPath(String imageUploadPath) {
		this.imageUploadPath = imageUploadPath;
	}

	public String getFlashUploadPath() {
		return flashUploadPath;
	}

	public void setFlashUploadPath(String flashUploadPath) {
		this.flashUploadPath = flashUploadPath;
	}

	public String getMediaUploadPath() {
		return mediaUploadPath;
	}

	public void setMediaUploadPath(String mediaUploadPath) {
		this.mediaUploadPath = mediaUploadPath;
	}

	public String getFileUploadPath() {
		return fileUploadPath;
	}

	public void setFileUploadPath(String fileUploadPath) {
		this.fileUploadPath = fileUploadPath;
	}

	public String getSmtpFromMail() {
		return smtpFromMail;
	}

	public void setSmtpFromMail(String smtpFromMail) {
		this.smtpFromMail = smtpFromMail;
	}

	public String getSmtpHost() {
		return smtpHost;
	}

	public void setSmtpHost(String smtpHost) {
		this.smtpHost = smtpHost;
	}

	public Integer getSmtpPort() {
		return smtpPort;
	}

	public void setSmtpPort(Integer smtpPort) {
		this.smtpPort = smtpPort;
	}

	public String getSmtpUsername() {
		return smtpUsername;
	}

	public void setSmtpUsername(String smtpUsername) {
		this.smtpUsername = smtpUsername;
	}

	public String getSmtpPassword() {
		return smtpPassword;
	}

	public void setSmtpPassword(String smtpPassword) {
		this.smtpPassword = smtpPassword;
	}

	public Integer getBuildHtmlDelayTime() {
		return buildHtmlDelayTime;
	}

	public void setBuildHtmlDelayTime(Integer buildHtmlDelayTime) {
		this.buildHtmlDelayTime = buildHtmlDelayTime;
	}

	public String getFrontUrl() {
		return frontUrl;
	}

	public void setFrontUrl(String frontUrl) {
		this.frontUrl = frontUrl;
	}

	public Integer getPort() {
		return port;
	}

	public void setPort(Integer port) {
		this.port = port;
	}

	public String getContextPath() {
		return contextPath;
	}

	public void setContextPath(String contextPath) {
		this.contextPath = contextPath;
	}

	public String getDefaultImg() {
		return defaultImg;
	}

	public void setDefaultImg(String defaultImg) {
		this.defaultImg = defaultImg;
	}

}
